Description:
PIOBCL detects situations where an integer overflow may occur as a result of
an arithmetic expression evaluation. Integer overflows may occur with addition,
subtraction, multiplication, or in shift left operations with
int operands
converted to
long.
Since an operation is performed with
int
operands, an overflow can happen before conversion.
An overflow can be avoided by converting one of the operation operands to a
long,
so the operation will be performed with
long operands.
This message is produced not only for explicit type conversions done by the programmer, but also for implicit type conversions performed by compiler.
Incorrect:
public long multiply(int a, int b) {
return a * b;
}
Correct:
public long multiply(int a, int b) {
return (long) a * b;
}